import 'package:cunyutech_flutter_ui/src/theme/main.dart';
import 'package:flutter/widgets.dart';

class SliverListEmpty extends StatefulWidget {
  SliverListEmpty({Key key, @required this.child, @required this.icon, this.onTap}) : super(key: key);
  final Widget child;
  final Widget icon;
  final VoidCallback onTap;

  _SliverListEmptyState createState() => _SliverListEmptyState();
}

class _SliverListEmptyState extends State<SliverListEmpty> {
  @override
  Widget build(BuildContext context) {
    Widget content = Container(
      margin: EdgeInsets.symmetric(vertical: CYMargin.Default),
      alignment: Alignment.center,
      child: Column(
        children: <Widget>[
          SizedBox(height: CYHeight.Large),
          widget.icon,
          SizedBox(height: CYMargin.Default),
          widget.child,
        ].where((item) => item != null).toList(),
      ),
    );

    if(widget.onTap!=null) {
      content = GestureDetector(onTap: widget.onTap, child: content);
    }

    return SliverToBoxAdapter(
      child: content,
    );
  }
}
